<template>
	<div>
		<div>
			<el-radio-group v-model="radio1" @change="ev_change(item)" v-for="(item,idx) in dateList" :key="idx">
				<el-radio-button :label="item.dateText"></el-radio-button>
			</el-radio-group>
		</div>
		<div class="block">
			<span class="demonstration">默认</span>
			<el-date-picker v-model="value1" type="datetimerange" range-separator="至" start-placeholder="开始日期"
				end-placeholder="结束日期" :picker-options="pickerOptions">
			</el-date-picker>
		</div>

	</div>
</template>

<script>
	export default {
		data() {
			return {
				radio1: '昨天2',
				value1: [],
				value2: '',
				nowTime: this.$moment(),
				pickerOptions: {},
				time: {
					start: 0,
					end: 0
				},
			}
		},
		props:{
			dateList:{
				type:Array,
				default(){
					return []
				}
			}
		},
		methods: {
			ev_change(item) {
				//昨日
				if (item.type == 0) {
					var yesStart = this.$moment().subtract(1, "day").format("YYYY-MM-DD 00:00:00")
					var yesEnd = this.$moment().subtract(1, "day").format("YYYY-MM-DD 23:59:59")
					this.value1 = [yesStart, yesEnd]
					this.time.start = Date.parse(yesStart)
					this.time.end = Date.parse(yesEnd)
					this.$emit('type', this.time)
					this.pickerOptions = {
						disabledDate(date) {
							return date.getTime() != Date.now() - 2 * 24 * 60 * 60 * 1000
						}
					}
					return false
				}
				//本日
				if (item.type == 1) {
					var todayStart = this.$moment().format("YYYY-MM-DD 00:00:00")
					this.value1 = [todayStart, this.nowTime]
					this.time.start = Date.parse(todayStart)
					this.time.end = Date.parse(this.nowTime)
					this.$emit('type', this.time)
					this.pickerOptions = {
						disabledDate(date) {
							return date.getTime() != Date.now() - 24 * 60 * 60 * 1000
						}
					}
					return false
				}
				//本周
				if (item.type == 2) {
					var weekStart = this.$moment().day(0).format("YYYY-MM-DD 00:00:00")
					this.value1 = [weekStart,this.nowTime]
					this.time.start = Date.parse(weekStart)
					this.time.end = Date.parse(this.nowTime)
					this.$emit('type', this.time)
					this.pickerOptions = {
						disabledDate:(date)=> {
							// return date.getTime() < new Date().getDay(0) || date.getTime() > Date.now()
							return date.getTime() <this.$moment().day(0) || date.getTime() > this.$moment()
						}
					}
					return false
				}
				//本月
				if (item.type == 3) {
					var monthStart = this.$moment().date(1).format("YYYY-MM-DD 00:00:00")
					this.value1 = [monthStart, this.nowTime]
					this.time.start = Date.parse(monthStart)
					this.time.end = Date.parse(this.nowTime)
					// console.log(this.time)
					this.$emit('type', this.time)
					this.pickerOptions = {
						disabledDate(date) {
							return date.getTime() < new Date().getDate(1) || date.getTime() > Date.now()
						}
					}
					return false
				}
				//自定义
				if (item.type == -1) {
					this.value1 = []
					this.pickerOptions = {
						disabledDate() {
							return false
						}
					}
					return false
				}
			}
		}
	}
</script>

<style>
</style>
